/*
 * $Id: Main.java 607 2008-08-27 07:00:23Z jasta00 $
 *
 * Copyright (C) 2008 Josh Guilfoyle <jasta@devtcg.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

package org.devtcg.five.music.activity;

import org.devtcg.five.music.R;
import org.devtcg.five.music.service.IPlaylistMoveListener;
import org.devtcg.five.music.service.IPlaylistService;
import org.devtcg.five.music.util.PlaylistUtil;

import android.app.Activity;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.DeadObjectException;
import android.os.RemoteException;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TextView;

public class Main extends TabActivity
{
	private static final String TAG = "Main";
	
	private ImageButton mPlayerNotif;

	private IPlaylistService mService;
	private Handler mHandler = new Handler();

	@Override
	public void onCreate(Bundle icicle)
	{
		super.onCreate(icicle);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);

        setDefaultTab(0);

        TabHost tabs = getTabHost();

        TabHost.TabSpec tab;
        Resources r = getResources();

        tab = tabs.newTabSpec("Artists");
        tab.setContent(new Intent().setClass(this, ArtistList.class));
        tab.setIndicator("Artists",
          r.getDrawable(R.drawable.tab_indicator_artist));
        tabs.addTab(tab);

        tab = tabs.newTabSpec("Albums");
        tab.setContent(new Intent().setClass(this, AlbumList.class));
        tab.setIndicator("Albums",
          r.getDrawable(R.drawable.tab_indicator_album));
        tabs.addTab(tab);

        /* XXX: This stuff is all hardcoded to use my Last.fm username, so
         * it just won't work for everyone... */
        tab = tabs.newTabSpec("Playlists");
        tab.setContent(new Intent().setClass(this, Playlists.class));
        tab.setIndicator("Playlists",
          r.getDrawable(R.drawable.tab_indicator_song));
        tabs.addTab(tab);

        tab = tabs.newTabSpec("More");
        tab.setContent(new Intent().setClass(this, More.class));
        tab.setIndicator("More");
        tabs.addTab(tab);

//        tab = tabs.newTabSpec("Last.fm");
//        tab.setContent(new Intent().setClass(this, Playlists.class));
//        tab.setIndicator(new MyTextIndicator(this, "Last.fm"));
//        tabs.addTab(tab);

//        tab = tabs.newTabSpec("Playlist");
//        tab.setContent(new Intent().setClass(this, Playlist.class));
//        tab.setIndicator(new MyTextIndicator(this, "Playlist"));
//        tabs.addTab(tab);

        mPlayerNotif = (ImageButton)findViewById(R.id.player_notif);
        mPlayerNotif.setOnClickListener(mGotoPlaylist);
        
//        bindService();
	}
	
//	private void bindService()
//	{
//		PlaylistUtil.bindService(this, mConnection);
//	}
//	
//	private void unbindService()
//	{
//		try {
//			if (mService != null)
//				mService.unregisterOnMoveListener(mMoveListener);
//		} catch (RemoteException e) {}
//
//		unbindService(mConnection);
//	}

	@Override
	public void onDestroy()
	{
//		unbindService();
		super.onDestroy();
	}

	private final OnClickListener mGotoPlaylist = new OnClickListener()
	{
		public void onClick(View v)
		{
			startActivity(new Intent(Main.this, Playlist.class));
		}
	};

//	private final ServiceConnection mConnection = new ServiceConnection()
//	{
//		public void onServiceConnected(ComponentName name, IBinder service)
//		{
//			mService = IPlaylistService.Stub.asInterface(service);
//
//			try
//			{
//				if (mService.isPlaying() == true)
//				{
//					mHandler.post(new Runnable() {
//						public void run()
//						{
//							mPlayerNotif.setVisibility(View.VISIBLE);
//						}
//					});
//				}
//
//				mService.registerOnMoveListener(mMoveListener);
//			}
//			catch (RemoteException e) {}
//		}
//
//		public void onServiceDisconnected(ComponentName name)
//		{
//			mService = null;
//		}
//	};
//	
//	private final IPlaylistMoveListener mMoveListener = new IPlaylistMoveListener.Stub()
//	{
//		private final Runnable mShow = new Runnable()
//		{
//			public void run()
//			{
//				mPlayerNotif.setVisibility(View.VISIBLE);
//			}
//		};
//		
//		private final Runnable mHide = new Runnable()
//		{
//			public void run()
//			{
//				mPlayerNotif.setVisibility(View.GONE);
//			}
//		};
//		
//		public void advance() {}
//		public void jump(int pos) {}
//		
//		public void pause()
//		{
//			mHandler.post(mHide);
//		}
//
//		public void play()
//		{
//			mHandler.post(mShow);
//		}
//
//		public void stop()
//		{
//			mHandler.post(mHide);
//		}
//
//		public void seek(long pos) {}
//		public void skip(long offs) {}
//	};
}
